package com.graduation.springbootinit.model.entity.ActivityPart;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Data
@TableName("community_activities_outfit_work")
public class OutfitWork {
    private static final ObjectMapper objectMapper = new ObjectMapper();
    
    @TableId(type = IdType.AUTO)
    private Long id;
    
    private Long challengeId;
    
    private Long userId;
    
    private String title;
    
    private String content;
    
    private String images;
    
    private Integer likeCount;
    
    /**
     * 最终排名
     */
    private Integer ranking;
    
    private Integer pointsReceived;
    
    private LocalDateTime createdAt;
    
    private LocalDateTime updatedAt;
    
    @TableField(exist = false)
    private List<String> imageList;
    
    public List<String> getImageList() {
        if (images == null || images.isEmpty()) {
            return new ArrayList<>();
        }
        try {
            return objectMapper.readValue(images, new TypeReference<List<String>>() {});
        } catch (JsonProcessingException e) {
            return new ArrayList<>();
        }
    }
    
    public void setImageList(List<String> imageList) {
        try {
            this.images = objectMapper.writeValueAsString(imageList);
        } catch (JsonProcessingException e) {
            this.images = "[]";
        }
    }
} 